package io.finer.erp.jeecg.bas.service.impl;

import io.finer.erp.jeecg.bas.entity.BasCustomerRegional;
import io.finer.erp.jeecg.bas.entity.BasRegionalManage;
import io.finer.erp.jeecg.bas.mapper.BasRegionalManageMapper;
import io.finer.erp.jeecg.bas.service.IBasCustomerRegionalService;
import io.finer.erp.jeecg.bas.service.IBasCustomerService;
import io.finer.erp.jeecg.bas.service.IBasRegionalManageService;

import java.util.Arrays;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

/**
 * @Description: 区域管理
 * @Author: jeecg-boot
 * @Date:   2021-03-30
 * @Version: V1.0
 */
@Service
public class BasRegionalManageServiceImpl extends ServiceImpl<BasRegionalManageMapper, BasRegionalManage> implements IBasRegionalManageService {

	@Autowired
	private IBasCustomerRegionalService customerRegionalService;
	
	@Override
	@Transactional(rollbackFor = Exception.class)
	public boolean deleteRegion(String regionId) {
		// TODO Auto-generated method stub
		LambdaQueryWrapper<BasCustomerRegional> queryWrapper = new LambdaQueryWrapper<>();
		queryWrapper.eq(BasCustomerRegional::getRegionId, regionId);
		customerRegionalService.remove(queryWrapper);
		this.removeById(regionId);
		return true;
	}

	@Override
	@Transactional(rollbackFor = Exception.class)
	public boolean deleteBatchRegion(String[] regionIds) {
		// TODO Auto-generated method stub
		LambdaQueryWrapper<BasCustomerRegional> queryWrapper = new LambdaQueryWrapper<>();
		queryWrapper.in(BasCustomerRegional::getRegionId, Arrays.asList(regionIds));
		customerRegionalService.remove(queryWrapper);
		this.removeByIds(Arrays.asList(regionIds));
		return true;
	}
}
